<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="title">
        <button data-url="/center">个人中心</button>
        <button data-url="/news">新闻</button>
        <button data-url="/music">音乐</button>
    </div>
    <div id="view"></div>

    <script>
        const oBtns = document.querySelectorAll('#title Button')
        const oView = document.querySelector('#view')

        const routes = [{
                path: '/center',
                content: '我的主页我做主'
            },
            {
                path: '/news',
                content: '明明我们看的新闻是一样的,为什么我要花钱看'
            },
            {
                path: '/music',
                content: '周董发新歌了在几个月前'
            }
        ]

        for (var i = 0; i < oBtns.length; i++) {
            oBtns[i].onclick=function(){
                location.hash = this.dataset.url
            }
        }

        window.onhashchange = function(e){
            const newURL = e.newURL.split('#')[1]

            routes.forEach(route=>{
                if(route.path === newURL){
                    oView.textContent = route.content
                }
            })
        }
    </script>


</body>

</html>